<template>
  <a-card :bordered="false">
    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="hanldleAdd()">上传结算</a-button>
      <!-- <a-button
      v-if="hasPerm('accountrecharge.Delete')"
        type="primary"
        icon="minus"
        @click="handleDelete(selectedRowKeys)"
        :disabled="!hasSelected()"
        :loading="loading"
      >删除</a-button> -->
      <a-button type="primary" icon="redo" @click="getDataList()">刷新</a-button>
    </div>

    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="4" :sm="24">
            <a-form-item label="查询类别">
              <a-select allowClear v-model="queryParam.condition">
                <a-select-option key="BusinessOrderNo">单号</a-select-option>
                <a-select-option key="PayingAccountName">客户名称</a-select-option>
                <a-select-option key="PayingAccount">充值账号</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24">
            <a-form-item>
              <a-input v-model="queryParam.keyword" placeholder="关键字" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button type="primary" @click="() => {this.pagination.current = 1; this.getDataList()}">查询</a-button>
            <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      :columns="columns"
      :rowKey="row => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="false"
      size="middle"
    >

      <!-- <span slot="action" slot-scope="text, record"> -->
        <!-- <template>
          
          <a-popconfirm title="确定删除吗？"
          v-if="hasPerm('accountrecharge.Delete')"
    ok-text="确定"
    cancel-text="取消"
    @confirm="handleDelete([record.Id])"
    @cancel="cancel"
  >
    <a href="#">删除</a>
  </a-popconfirm>
        </template> -->
      <!-- </span> -->
    </a-table>

    <settlement-upload ref="SettlementUpload" :parentObj="this"></settlement-upload>
  </a-card>
</template>

<script>
import SettlementUpload from './SettlementUpload'

const columns = [
  { title: '结算批次号', dataIndex: 'BatchNo', width: '15%' },
  { title: '企业名称', dataIndex: 'MerchantName', width: '15%' },
  { title: '提交时间', dataIndex: 'CreateTime', width: '17%' },
  { title: '结算笔数', dataIndex: 'TotalNum', width: '13%' },
  
  { title: '结算金额', dataIndex: 'TotalAmount', width: '15%' },
  { title: '状态', dataIndex: 'BatchStt', width: '15%' },
  { title: '操作', dataIndex: 'action', scopedSlots: { customRender: 'action' } }
]

export default {
  components: {
    SettlementUpload
  },
  mounted() {
    this.getDataList()
  },
  data() {
    return {
      data: [],
      pagination: {
        current: 1,
        pageSize: 10,
        showSizeChanger: true,
        showQuickJumper: true,
        total: 0, // 总数，必须先有
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        onShowSizeChange: (current, pageSize) => {
          this.pagination.current = 1;
          this.pagination.pageSize = pageSize;
          this.getDataList(); //显示列表的接口名称
        },
        // 改变每页数量时更新显示
        onChange: (current, size) => {
          this.pagination.current = current;
          this.pagination.pageSize = size;
          this.getDataList();
        },
      },
      filters: {},
      sorter: { field: 'Id', order: 'asc' },
      loading: false,
      columns,
      queryParam: {},
      selectedRowKeys: []
    }
  },
  methods: {
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.sorter = { ...sorter }
      this.getDataList()
    },
    getDataList() {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/Base_leasesystem_transactionbatch/leasesystem_transactionbatch/GetDataList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
          ...this.filters
        })
        .then(resJson => {
          console.log(resJson)
          this.loading = false
          this.data = resJson.Data
          const pagination = { ...this.pagination }
          pagination.total = resJson.Total
          this.pagination = pagination
        })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    hanldleAdd() {
      this.$refs.SettlementUpload.openForm()
    },
    handleEdit(id) {
      this.$refs.editForm.openForm(id)
    },
    handleDelete(ids) {
      var thisObj = this

          return new Promise((resolve, reject) => {
            thisObj.$http.post('/Base_leasesystem_transactionbatch/leasesystem_transactionbatch/DeleteData', ids).then(resJson => {
              resolve()

              if (resJson.Success) {
                thisObj.$message.success('操作成功!')

                thisObj.getDataList()
              } else { 
                thisObj.$message.error(resJson.Msg)
              }
            })
          })
       
    },
    cancel(e) {
      this.$message.error('已取消删除');
    }
  }
}
</script>

<style>
.ant-table-thead > tr > th
{
  font-weight: 600;
  color: #333333;
}
</style>